using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.bonus
{
[System.Serializable]
public  class CopyBonus : Bonus
 {

    public cfg.bonus.Bonus bonus ;
     public int num ;
     


    public const int TYPE_ID = 994234127;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(2);
        os.WriteSize(Tag.BEAN | (1 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_bonus_Bonus(bonus,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.INT | (2 << Tag.TAG_SHIFT));  os.WriteInt(num);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.BEAN | (1 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); bonus = cfg.Extensions.unmarshal_compatible_cfg_bonus_Bonus(os); os = _oldOs; break; }   
             case (Tag.INT | (2 << Tag.TAG_SHIFT)):   num = os.ReadInt(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "CopyBonus");
        ele.WriteStartElement("bonus"); ele.WriteAttributeString("id", "1"); cfg.Extensions.xml_marshal_cfg_bonus_Bonus(bonus,ele); ele.WriteEndElement();
         ele.WriteStartElement("num"); ele.WriteAttributeString("id", "2"); ele.WriteInt(num); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  bonus = cfg.Extensions.xml_unmarshal_cfg_bonus_Bonus(ele); break; 
                 case 2:  num = ele.ReadInt(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "bonus":  bonus = cfg.Extensions.xml_unmarshal_cfg_bonus_Bonus(ele); break; 
                 case "num":  num = ele.ReadInt(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
